// 基于template/src/router/routes/view-route.ts.hbs生成
import qs from 'qs';
import AuthGuard from '../guard/auth-guard';
import { EntityRoute } from './entity-route';
import { userIndexRoute } from './user-route';

const viewRoute = [
{{#if app.defaultPSAppIndexView}}
    {
        path: '/index/:index?',
        name: 'index',
        meta: {
            caption: '{{app.defaultPSAppIndexView.caption}}',
            tag: '{{app.defaultPSAppIndexView.codeName}}',
            requireAuth: false,
            ignoreAddPage: false,
            startPage: true,
            parameters: [
                { pathName: 'views', parameterName: 'index' },
            ],
        },
        beforeEnter: (to: any, from: any, next: any) => {
            to.defaultPage = true;
            const routerParamsName = 'index';
            const params: any = {};
            if (to.params && to.params[routerParamsName]) {
                Object.assign(params, qs.parse(to.params[routerParamsName], { delimiter: ';' }));
            }
            const url: string = '/appdata';
            const auth: Promise<any> = AuthGuard.getInstance().authGuard(url, params);
            auth.then((result: any) => {
                next(result ? true : false);
            }).catch(() => {
                next(false);
            })
        },
        component: () => import("@views/{{#if app.defaultPSAppIndexView.psAppModule.codeName}}{{spinalCase app.defaultPSAppIndexView.psAppModule.codeName}}/{{/if}}{{spinalCase app.defaultPSAppIndexView.codeName}}/{{spinalCase app.defaultPSAppIndexView.codeName}}.vue"),
        children: [
    {{#each app.pages as | page |}}
        {{#and (neq page.codeName app.defaultPSAppIndexView.codeName) (eq page.type 'APPINDEXVIEW')}}
            {
                path: 'views/{{lowerCase page.codeName}}',
                meta: {
                    caption: '{{page.caption}}',
                    captionLanResTag: '{{page.capPSLanguageRes.lanResTag}}',
                    tag: '{{page.codeName}}',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/{{#if page.psAppModule.codeName}}{{spinalCase page.psAppModule.codeName}}/{{/if}}{{spinalCase page.codeName}}/{{spinalCase page.codeName}}.vue"),
            },
        {{/and}}
        {{#and (eq page.type 'APPPORTALVIEW')}}
            {
                path: 'views/{{lowerCase page.codeName}}',
                meta: {
                    caption: '{{page.caption}}',
                    captionLanResTag: '{{page.capPSLanguageRes.lanResTag}}',                    
                    tag: '{{page.codeName}}',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/{{#if page.psAppModule.codeName}}{{spinalCase page.psAppModule.codeName}}/{{/if}}{{spinalCase page.codeName}}/{{spinalCase page.codeName}}.vue"),
            },
        {{/and}}
        {{#and (eq page.type 'APPPANELVIEW')}}
            {
                path: 'views/{{lowerCase page.codeName}}',
                meta: {
                    caption: '{{page.caption}}',
                    captionLanResTag: '{{page.capPSLanguageRes.lanResTag}}',                    
                    tag: '{{page.codeName}}',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/{{#if page.psAppModule.codeName}}{{spinalCase page.psAppModule.codeName}}/{{/if}}{{spinalCase page.codeName}}/{{spinalCase page.codeName}}.vue"),
            },
        {{/and}}
        {{#and (eq page.type 'APPWFREDIRECTVIEW')}}
            {
                path: 'appwfdataredirectview/:appwfdataredirectview?',
                meta: {
                    caption: '{{page.caption}}',
                    captionLanResTag: '{{page.capPSLanguageRes.lanResTag}}',                    
                    tag: '{{page.codeName}}',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                        { pathName: 'views', parameterName: 'index' },
                    ],
                },
                component: () => import("@views/{{#if page.psAppModule.codeName}}{{spinalCase page.psAppModule.codeName}}/{{/if}}{{spinalCase page.codeName}}/{{spinalCase page.codeName}}.vue"),
            },
        {{/and}}
    {{/each}}
            {
                path: '/appredirectview',
                meta: {
                    caption: '全局应用重定向视图',
                    tag: 'AppRedirectView',
                    requireAuth: false,
                    ignoreAddPage: true,
                    startPage: false,
                    parameters: [
                        { pathName: 'appredirectview', parameterName: 'appredirectview' },
                        { pathName: 'views', parameterName: 'view' }
                    ],
                },
                //  component: () => import('@components/app-redirect-view/app-redirect-view.vue')
            },
            {
                path: 'apphtmlview/:apphtmlview?',
                meta: {
                    caption: '应用HTML视图',
                    tag: 'AppHtmlView',
                    requireAuth: false,
                    ignoreAddPage: false,
                    startPage: false,
                    parameters: [
                      { pathName: 'apphtmlview', parameterName: 'apphtmlview' },
                      { pathName: 'views', parameterName: 'view' },
                    ],
                },
                component: () => import('@components/function/html-container/src/html-container.vue'),
            },
            ...EntityRoute,
        ]
    },
{{/if}}
    {
        path: '/login/:login?',
        name: 'login',
        meta: {
            caption: '登录',
            tag: 'AppLoginView',
            requireAuth: false,
            ignoreAddPage: true,
            startPage: false
        },
        component: () => import('@components/function/login/src/login.vue'),
        {{!-- {{#each app.pages as | page |}}{{#and page.refFlag (eq page.viewType "APPLOGINVIEW")}}component: () => import("@views/{{#if page.psAppModule.codeName}}{{spinalCase page.psAppModule.codeName}}/{{/if}}{{spinalCase page.codeName}}/{{spinalCase page.codeName}}.vue"),{{/and}}{{/each}} --}}
    },
    {
        path: '/404',
        meta: {
            caption: '404',
            tag: 'AppNotFoundView',
            ignoreAddPage: true,
            requireAuth: false,
            startPage: false
        },
        component: () => import('@components/function/404/src/404.vue'),
    },
    {
        path: '/500',
        meta: {
            caption: '500',
            tag: 'AppErrorView',
            ignoreAddPage: true,
            requireAuth: false,
            startPage: false
        },
        component: () => import('@components/function/500/src/500.vue'),
    },
    {
        path: '/lock',
        meta: {
            caption: 'lock',
            tag: 'AppLockView',
            ignoreAddPage: true,
            requireAuth: false,
            startPage: false
        },
        component: () => import('@components/function/lock/src/lock.vue'),
    },
    ...userIndexRoute
]

export const ViewRoute = viewRoute;